<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-33268549-3', 'xem24.com');
  ga('send', 'pageview');

</script>
<!--<div id="sunnet_widget_44" style="display: block;padding:5px;clear:both;top:3px;">
    
    <script type="text/javascript">var is_load_sunnet_lib = is_load_sunnet_lib || 1;if(is_load_sunnet_lib == 1) {is_load_sunnet_lib = 2;if(typeof(jQuery)=='undefined') {document.write(unescape("%3Cscript src='http://amobi.vn/js/default/jquery-1.7.2.min.js' type='text/javascript'%3E%3C/script%3E"));}document.write(unescape("%3Cscript src='http://amobi.vn/js/default/sunnet.js' type='text/javascript'%3E%3C/script%3E"));}</script>
    <script type="text/javascript" src="http://amobi.vn/index/widget?widget_id=44"></script>    </center>    
        
</div> -->
<div id="video" style="clear:both;">
    <!--<h2 class="video-title"><center>Danh sách  chọn lọc  100 bài</center></h2> -->
    <script language="javascript">
			$(document).ready(function(){
				var width = $(window).width()*0.9;
				var height = width*0.6;
				var width_max = 640;
				var height_max = 360;
				if(width > width_max){
					$('#player').css('width', width_max);
					$('#player').css('height', height_max);
				}else{
					$('#player').css('width', width);
					$('#player').css('height', height);
				}
				
				$(window).resize(function() {
					width = $(window).width()*0.9;
					height = width*0.6;
					if(width > width_max){
					$('#player').css('width', width_max);
					$('#player').css('height', height_max);
					}else{
						$('#player').css('width', width);
						$('#player').css('height', height);
					}
				})
			})
    </script>
    <center><div class="container_player"><center><div class="vendor"><div id="player"></div></div></center></div></center>
	<script>
    var hash = window.location.hash;//Lay thong so #ep
    if(hash != ''){
            hash = hash.split('#ep');
            hash = hash[1].split('-');
            hash = hash[0];
    }else hash = 1;
    
	var tag = document.createElement('script');
    tag.src = "//www.youtube.com/iframe_api";
    var firstScriptTag = document.getElementsByTagName('script')[0];
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
	var player;
	var playlist = [<?php echo $this->ids;?>];
	function onYouTubePlayerAPIReady() {
		 player = new YT.Player('player', {
          //height: '100%',
          //width: '98%',
		  playerVars: {
            'autoplay': 0,
            'controls': 1,
          },
          events: {
            'onReady': onPlayerReady,
            'onStateChange': onPlayerStateChange,
            //'onPlaybackQualityChange': testfunc(),
          }
        });
	}
	function onPlayerReady(event) { 
		event.target.cuePlaylist(playlist,hash-1); 
	}
      //var done = false;
    var flag_start = 0;
    var flag_play  = 0;
    var text = "";
    var tap = hash-2;
    var href = window.location.href;
    tmp_href = href.split('#ep');
    //if(tmp_href[1] == null) tmp_href = href.split('.html');
    href = tmp_href[0];
    function onPlayerStateChange(event) {
        if(event.data == -1) flag_start = 1;
        if(event.data == 1) flag_play = 1;
        
        if(flag_start == 1 && flag_play == 1){
            tap++;
            text = $('#ep-'+tap).text();//lay tieu de cua tap phim
            text = locdau(text);//o dau tieu de
            
            $('.episode').removeClass('playing');
            $('.ep-'+tap).addClass('playing');
            window.location.replace(href+'#ep'+tap+'-'+text);//day ep len url
            
            flag_start = 0;
            flag_play  = 0;
        }
    }
    function stopVideo() {
        player.stopVideo();
	}
    function playAt(ep){
        player.playVideoAt(ep+1);
        tap = ep;
    }
    function playNext()
    {
        //clickAds();
        var number_eps = $(".episode").length;
        hash = window.location.hash;//Lay thong so #ep
        hash = hash.split('#ep');
        hash = hash[1].split('-');
        hash = parseInt(hash[0]);
        hash = hash+1;
        if(hash > 0){
            player.playVideoAt(hash);
            tap = hash-1;        
        }else{
            alert("Không còn tập nào phía sau.");
        }
    }
    function playPrev()
    {
        hash = window.location.hash;//Lay thong so #ep
        hash = hash.split('#ep');
        hash = hash[1].split('-');
        hash = parseInt(hash[0]);
        hash = hash-1;
        if(hash > 0){
            player.playVideoAt(hash);
            tap = hash-1;        
        }else{
            alert("Không còn tập nào phía trước.");
        }
    }
    
	function getCookie(c_name)
	{
		var c_value = document.cookie;
		var c_start = c_value.indexOf(" " + c_name + "=");
		if (c_start == -1)
		  {
		  c_start = c_value.indexOf(c_name + "=");
		  }
		if (c_start == -1)
		  {
		  c_value = null;
		  }
		else
		  {
		  c_start = c_value.indexOf("=", c_start) + 1;
		  var c_end = c_value.indexOf(";", c_start);
		  if (c_end == -1)
			{
			c_end = c_value.length;
			}
		  c_value = unescape(c_value.substring(c_start,c_end));
		  }
		return c_value;
	}
    function locdau(str) {
      str= str.toLowerCase();
      str= str.replace(/à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ/g,"a");
      str= str.replace(/è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ/g,"e");
      str= str.replace(/ì|í|ị|ỉ|ĩ/g,"i");
      str= str.replace(/ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ/g,"o");
      str= str.replace(/ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ/g,"u");
      str= str.replace(/ỳ|ý|ỵ|ỷ|ỹ/g,"y");
      str= str.replace(/đ/g,"d");
      str= str.replace(/!|@|%|\^|\*|\(|\)|\+|\=|\<|\>|\?|\/|,|\.|\:|\;|\'| |\"|\&|\#|\[|\]|~|$|_/g,"-");
        /* tìm và thay thế các kí tự đặc biệt trong chuỗi sang kí tự - */
      str= str.replace(/-+-/g,"-"); //thay thế 2- thành 1-
      str= str.replace(/^\-+|\-+$/g,"");
        //cắt bỏ ký tự - ở đầu và cuối chuỗi
      return str;
     } 
	</script>
    
    <div id="btn-tools">
    <div id="btn-controls">
        <a class="btn-control prev-btn" title="Tập trước" onclick="playPrev()">&nbsp;</a>
        <a class="btn-control next-btn" title="Tập tiếp" onclick="playNext()">&nbsp;</a>
		<a href="#">Danh sách  chọn lọc  100 bài</a>
    </div>
 <!--   <div id="fb-root" style="float: right;display: none"></div>
    <script>(function(d, s, id) {
      var js, fjs = d.getElementsByTagName(s)[0];
      if (d.getElementById(id)) return;
      js = d.createElement(s); js.id = id;
      js.src = "//connect.facebook.net/vi_VN/all.js#xfbml=1";
      fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));</script>
    <div style="float: right;width: 135px; display: block;overflow: hidden;-webkit-overflow-scrolling: touch;"class="fb-like" data-href="<?php echo $url?>" data-send="true" data-layout="button_count" data-width="100" data-show-faces="true" data-font="tahoma"></div>
    <div style="float: right;">
    <div class="clear"></div>
    <g:plusone size='medium'></g:plusone>

    <script type="text/javascript">
        window.___gcfg = {
            lang: 'en-US'
        };

      (function() {
        var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
        po.src = 'https://apis.google.com/js/plusone.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
      })();
    </script>
    </div>-->
        <div class="clear"></div>
    </div>
    <div id="list-eps">
        <ul>
        <?php
             $modelR = new RemoveCircumflex();
             $name_eps = stripslashes($this->titles);
            
                $name_eps  = explode('#|#',$name_eps);
                for($i = 0;$i<count($name_eps);$i++){
                    if($name_eps[$i] != "")
                        echo "<li class='episode ep-".($i+1)."'><span>".($i+1)."</span><a id='ep-".($i+1)."' href='#ep".($i+1)."-".$modelR->rewrite($name_eps[$i])."' onclick='playAt(".$i.")'>".$name_eps[$i]."</a></li>";
                    else 
                        echo "<li class='episode ep-".($i+1)."'><span>".($i+1)."</span><a id='ep-".($i+1)."' href='#ep".($i+1)."' onclick='playAt(".$i.")'>Xem</a></li>";
                }
         ?>
         </ul>
    </div>
    <!--<div class="content-block box-comment">
        <h2 class="label_top">Bình luận</h2>
        <!--
        <div id="_commentNotiBox">
            <p class="notification attention">Chỉ chấp nhận bình luận bằng tiếng Việt có dấu, những bình luận sai quy định sẽ bị xóa</p>
        </div>
        
        <div class="comment-form">
            <div id="fb-root"></div>
            <script>(function(d, s, id) {
              var js, fjs = d.getElementsByTagName(s)[0];
              if (d.getElementById(id)) return;
              js = d.createElement(s); js.id = id;
              js.src = "//connect.facebook.net/vi_VN/all.js#xfbml=1";
              fjs.parentNode.insertBefore(js, fjs);
            }(document, 'script', 'facebook-jssdk'));</script>
            <div class="fb-comments" data-href="http://xem24.com/box-ca-nhac.html" data-width="470" data-num-posts="10"></div>
        </div>
    </div>-->
</div>